% algorithm
%
% - if there is some overlap, then the distance is zero
% - if there is no overlap, then the distance is between the close of the one happening first and
%   the open of the one happening last
%
function fDistance = GetDistanceBetweenTwoTransitions( aiFirstTransition, aiSecondTransition )
	% 
	% case there is some overlap
	if	(																...
			(	... case where the opening of the second transition is inside the first transition
					(aiFirstTransition(1)	<= aiSecondTransition(1))	...
				&&	(aiSecondTransition(1)	<= aiFirstTransition(2))	...
			)															...
			||															...
			(	... case where the closing of the second transition is inside the first transition
					(aiFirstTransition(1)	<= aiSecondTransition(2))	...
				&&	(aiSecondTransition(2)	<= aiFirstTransition(2))	...
			)															...
		)
		%
		fDistance = 0;
		%
	else%
		%
		% case where the first transition happens entirely before the second
		if(  aiFirstTransition(2) < aiSecondTransition(1)  )
			%
			fDistance = abs( aiFirstTransition(2) - aiSecondTransition(1) );
			%
		else%
			%
			% viceversa, where the second transition happens entirely before the first
			fDistance = abs( aiSecondTransition(2) - aiFirstTransition(1) );
			%
		end;%
		%
	end;%
	%
	% DEBUG
% 	fprintf('First  transition: %d - %d\n', aiFirstTransition(1), aiFirstTransition(2));
% 	fprintf('Second transition: %d - %d\n', aiSecondTransition(1), aiSecondTransition(2));
% 	fprintf('Distance:          %d\n', fDistance);
% 	pause
	%
end % function

